import React, { Component } from 'react';
import PropTypes  from 'prop-types'

class XiaojiejieItem extends Component {
    constructor(props){
        super(props)
        this.handleClick = this.handleClick.bind(this)
    }

    //满足条件：组件第一次存在dom中，函数是不会执行，
    //如果已经存在于dom中，函数才会被执行
    componentWillReceiveProps(){
        console.log('child - componentWillReceivePropes')
    }

    //unmounting
    componentWillUnmount(){
        console.log('child - componentWillUnmount')
    }
    
    shouldComponentUpdate(nextProps,nextState){
        if(nextProps.content !== this.props.content){
            return true
        }else{
            return false
        }
    }
    render() { 
        return ( 
            <li onClick={this.handleClick}>{this.props.avname}为你服务-{this.props.content}</li>
         );
    }
    handleClick(){
        this.props.deleteClik(this.props.index)
    }
}
//规定父组件传入值得类型
XiaojiejieItem.propTypes ={
    avname:PropTypes.string.isRequired,
    content:PropTypes.string,
    index:PropTypes.number,
    deleteClik:PropTypes.func
}
// 传入默认值
XiaojiejieItem.defaultProps={
    avname:"大熊"
}
 
export default XiaojiejieItem;